/**
 * 
 */
package org.freetek.linkdn.activity.home;

import org.freetek.linkdn.CommonBundleKeys;
import org.freetek.linkdn.LinkdnActivity;
import org.freetek.linkdn.R;
import org.freetek.linkdn.util.communication.LinkedInUpdatesWrapper;
import org.freetek.linkdn.util.model.LinkedInUpdatesResponse;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class HomeActivity extends LinkdnActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
//		
//		LinkedInUpdatesWrapper updates = new LinkedInUpdatesWrapper();
//		updates.getUpdates(getAuthResponse(), verifier);
		
		View btnUpdates = findViewById(R.id.BtnUpdates);
		btnUpdates.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				LinkedInUpdatesWrapper updatesWraper = new LinkedInUpdatesWrapper();
				LinkedInUpdatesResponse updates = updatesWraper.getUpdates(getAuthResponse(), getVerifier());
				
				// TODO this should call the future update activity
				startActivityForResult(getAlertIntent(updates.getRaw()), RESULT_FIRST_USER);
			}
		});
	}
	
	private Bundle getArgs() {
		Bundle result = getExtras();
		
		if (null == result || result.size() < 1) {
			throw new IllegalArgumentException("extras bundle missing");
		}
		if (!result.containsKey(CommonBundleKeys.VERIFIER)) {
			throw new IllegalArgumentException("extras bundle does not contain " + CommonBundleKeys.VERIFIER + " key");
		}
		return result;
	}
	
	private String getVerifier() {
		return getArgs().getString(CommonBundleKeys.VERIFIER);
	}
}
